(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  define(['chaplin'], function(Chaplin) {
    'use strict';
    var BaseModel, _ref;
    return BaseModel = (function(_super) {
      __extends(BaseModel, _super);

      function BaseModel() {
        _ref = BaseModel.__super__.constructor.apply(this, arguments);
        return _ref;
      }

      BaseModel.prototype.saveAsJSON = function() {
        var ajaxPromise, json, promise, type,
          _this = this;
        json = this.toJSON();
        promise = $.Deferred();
        type = this.id != null ? 'update' : 'create';
        ajaxPromise = Backbone.sync(type, this, {
          url: this.url(),
          dataType: 'json',
          contentType: 'application/json; charset=UTF-8',
          data: window.JSON.stringify(json)
        });
        ajaxPromise.fail(function() {
          return promise.reject.apply(_this, arguments);
        }).done(function(json, status, ajaxObj) {
          return promise.resolve.apply(_this, [json, ajaxObj]);
        });
        return promise;
      };

      BaseModel.prototype.fetch = function() {
        this.fetched = true;
        return BaseModel.__super__.fetch.apply(this, arguments);
      };

      return BaseModel;

    })(Chaplin.Model);
  });

}).call(this);
